<template>
  <div class="about">
    <h1>This is an about page</h1>
    <div style="text-align: center">
      <el-transfer
        style="text-align: left; display: inline-block"
        v-model="value4"
        filterable
        :filter-method="remoteSearch"
        :left-default-checked="[2, 3]"
        :right-default-checked="[1]"
        :titles="['Source', 'Target']"
        :button-texts="['到左边', '到右边']"
        :format="{
          noChecked: '${total}',
          hasChecked: '${checked}/${total}'
        }"
        @change="handleChange"
        :data="mockList"
      >
        <span slot-scope="{ option }">{{ option.key }} - {{ option.label }}</span>
        <el-button class="transfer-footer" slot="left-footer" size="small">操作</el-button>
        <el-button class="transfer-footer" slot="right-footer" size="small">操作</el-button>
      </el-transfer>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
  name: 'AboutView',
  data() {
    return {
      value: [1],
      value4: [1]
    };
  },
  computed: {
    ...mapGetters(['permission/getMockList', 'permission/searchMockList']),
    mockList() {
      return this['permission/getMockList'];
    }
  },
  mounted() {
    this.$store.dispatch('permission/generateMockList');
  },
  methods: {
    remoteSearch(query, item) {
      if (query) {
        const list = this['permission/searchMockList'](query);
        const isMatch = list.some((listItem) => listItem.key === item.key && listItem.label === item.label);
        return isMatch;
      }
      return this.mockList;
    },
    handleChange(value, direction, movedKeys) {
      console.log(value, direction, movedKeys);
    }
  }
};
</script>
